#pragma once
#include <memory>
#include "lock.h"

#define WM_WRITELOG  WM_USER + 101

class LogThread {
public:
    ~LogThread();
    static LogThread* Get();

    void Start();
    void Stop();

    void PostThreadMessag(UINT msg, WPARAM wparam, LPARAM lparam);
    void Run();
private:
    LogThread();

    void HandleMessage(MSG* msg);
    void OnWriteLog(WPARAM wparam, LPARAM lparam);

private:
    HANDLE thread_;
    unsigned int thread_id_;
    volatile LONG slog_ref_;
    Lock slog_ref_lock_;

    static std::shared_ptr<LogThread> log_thread_;
};